/**
 * 
 * @author  phoenics@126.com
 * @version v.0.1
 * @date  2018年6月17日 下午7:19:00 
 * 
 */
package phoenics.upservice.service;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import phoenics.common.exception.BaseException;
import phoenics.upservice.auth.JwtAuthentication;
import phoenics.upservice.entity.User;

/**
 *
 */
@Service  
public class UserService {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(UserService.class);
	public User takePrincipal() {
		JwtAuthentication j=(JwtAuthentication)SecurityContextHolder.getContext().getAuthentication();
		if(j==null) {
			throw new BaseException(-1,"未登录");
		}
		if(j.getPrincipal()==null) {
			throw new BaseException(-1,"未登录");
		}
		return (User)j.getPrincipal();
	}
}
